{extend name="public/base" /}

{block name="title"}添加广告{/block}

{block name="main"}
<div class="layui-tab" id="Js_title_navigation">
    <ul class="layui-tab-title">
        <li class="layui-this">添加广告</li>
    </ul>
</div>
<blockquote class="layui-elem-quote">
    <b>{$adposition['name']}</b> : 广告图片尺寸建议：宽{$adposition['width']} * 高{$adposition['height']}像素(px)
</blockquote>
<form class="layui-form layui-row " action="" method="post">    
    <input type="hidden" name="pid" value="{$pid}" />
	<div class="layui-col-xs12" style="padding-bottom: 50px;">
        <div class="layui-form-item ">
			<label class="layui-form-label">
                <span class="e-input-required" >*</span>广告图片：</label>
			<div class="layui-input-block">
                <input type="hidden" name="pic" value="" id="JS_upImg_input" />
                <div class="e-upload-img" id="JS_upload_img" style="display: none;"><img src="" /></div>                    
                <button type="button" class="layui-btn" id="JS_upload_btn">
                    <i class="layui-icon">&#xe67c;</i>上传图片</button>
			</div>
		</div>   
        <div class="layui-form-item layui-col-md4">
			<label class="layui-form-label">开始时间：</label>
			<div class="layui-input-block">
				<input type="text" name="starttime" id="starttime" value="{:date('Y-m-d H:i:s')}" placeholder="广告展示开始时间" class="layui-input" />
			</div>
		</div>
        <div class="layui-form-item layui-col-md4">
			<label class="layui-form-label">结束时间：</label>
			<div class="layui-input-block">
				<input type="text" name="endtime" id="endtime" value="" placeholder="广告展示结束时间" class="layui-input" />
			</div>
		</div>
        
		<div class="layui-form-item layui-col-md4">
			<label class="layui-form-label">
                <span class="e-input-required" >*</span>广告名称：</label>
			<div class="layui-input-block">
				<input type="text" name="name" value="" placeholder="广告名称" lay-verify="required" class="layui-input" />
			</div>
		</div>
        <div class="layui-form-item layui-col-md4">
			<label class="layui-form-label">跳转连接：</label>
			<div class="layui-input-block">
				<input type="text" name="url" value="" placeholder="请输入广告点击跳转的url" class="layui-input" />
			</div>
		</div>
        <div class="layui-form-item layui-col-md4">
			<label class="layui-form-label">排序：</label>
			<div class="layui-input-block">
				<input type="text" name="sort" value="50" placeholder="广告排序,数值越大排序越前" lay-verify="number" class="layui-input" />
			</div>
		</div>
        
		<div class="layui-form-item layui-col-md4">
			<label class="layui-form-label">简介：</label>
			<div class="layui-input-block">
                <textarea name="des" placeholder="请输入广告的备注或简介" class="layui-textarea"></textarea>
			</div>
		</div>
        
         
	</div>
    <div class="layui-layout-admin" >
        <div class="layui-footer" style="left:0;">
            <div class="layui-form-item">
                <a href="javascript:;" class="layui-btn layui-btn-primary" onclick="javascript:history.back();">返回</a>
				<button type="button" class="layui-btn" lay-submit="" lay-filter="addFrom">立即添加</button>
			</div>
        </div>
    </div>

</form>
{/block}
{block name="script"}
<script>
layui.use(['form','common','laydate','uploadimg'],function(){
    var form = layui.form;
    
    //日期
    layui.laydate.render({ elem: '#starttime',min: 0 ,type: 'datetime'});
    layui.laydate.render({ elem: '#endtime',min: 0,type: 'datetime'});
    
    // 图片上传图片
    layui.uploadimg.render({
        saveH : "{$adposition['height']}",
        saveW : "{$adposition['width']}",
        elem : '#JS_upload_btn',
        url  : '/sys/Upload/image', //上传接口
        type : 'advert',
        done : function(ret){
            if( ret.code == 1 ){
                $('#JS_upload_img').show();
                $('#JS_upload_img img').attr('src',ret.data);
                $('#JS_upImg_input').val(ret.data);
            }else{
                layui.common.tip(ret.msg);
            }
        }
    }); 
    
    form.on('submit(addFrom)',function(data){        
        if( data.field.pic == '' ){
            layui.common.error('请先上传广告图片');
            return false;
        }
        layui.common.post('/set/ad/add',data.field);
        return false;
    });    
    form.render(); //更新全部
})
</script>
{/block}